/**
 * 量筒
 */
Cylinder = Widget.extend({
	runningAction:null,
	action:null,
	ctor:function(parent,action){
		this._super(parent,action);
		this.init();
		this.action=action;
		if(this.action==ACTION_DO1){
			this.setTag(TAG_CYLINDER_ALL);
		}else{
			this.setTag(TAG_CYLINDER1_ALL);
		}
	},
	init:function(){
		this.body = new Button(this, 10, TAG_CYLINDER, "#cylinder.png", this.callback,this);
		this.body.setAnchorPoint(cc.p(0.5, 0.7));
		
		var film=new Button(this.body,10,TAG_FILM,"#film.png",this.callback,this);
		film.setPosition(cc.p(this.body.width*0.5,this.body.height*0.12));
		film.setScale(0.3);
		film.setOpacity(0);
		
		var show=new Button(this.body,10,TAG_SHOW,"#show.png",this.callback,this);
		show.setPosition(cc.p(this.body.width*2,this.body.height*0.85));
		show.setOpacity(0);
		
		var flow=new Button(this.body,10,TAG_FLOW_LEFT,"#flow_left.png",this.callback,this);
		flow.setRotation(-85);
		flow.setAnchorPoint(cc.p(1, 1));
		flow.setPosition(cc.p(this.body.width*0.82, this.body.height*1.08));
		flow.setOpacity(0);
	},
	rotate:function(){
		var rotate1=cc.rotateBy(1,5);
		this.body.runAction(rotate1);
	},
	rotate1:function(){
		var rotate1=cc.rotateBy(1,5);
		this.body.runAction(rotate1.reverse());
	},
	//水位线
	showFilm:function(){
		var film=this.body.getChildByTag(TAG_FILM);
		var fadein=cc.fadeIn(0.5);
		var move=cc.moveBy(1, cc.p(0, this.body.height*0.22));	
		film.runAction(cc.sequence(fadein,move));
	},
	//特写
	show:function(){
		var fadein=cc.fadeIn(0.5);
		var fadeout=cc.fadeOut(0.5);
		var show=this.body.getChildByTag(TAG_SHOW);
		show.runAction(cc.sequence(fadein,cc.delayTime(1),fadeout));
	},
	//显示水流
	showFlow:function(){
		var fadein=cc.fadeIn(0.5);
		var fadeout=cc.fadeOut(0.5);
		var flow=this.body.getChildByTag(TAG_FLOW_LEFT);
		flow.runAction(cc.sequence(fadein,cc.delayTime(1),fadeout));
	},
	filmAction:function(){
		var move2=cc.moveBy(2,cc.p(0,-this.body.height*0.2));
		var rotate=cc.rotateBy(1,85);
		var scale=cc.scaleBy(1,2.5);
		var fadeout=cc.fadeOut(0.5)
		var film=this.body.getChildByTag(TAG_FILM);
		var beaker=ll.run.getChildByTag(TAG_BEAKER_ALL);
		film.runAction(cc.sequence(cc.spawn(rotate.reverse(),scale),cc.spawn(move2,cc.callFunc(function() {
			beaker.showLine();
			this.showFlow();
		}, this)),fadeout));
	},
	filmAction1:function(){
		var move2=cc.moveBy(2,cc.p(0,-this.body.height*0.2));
		var rotate=cc.rotateBy(1,85);
		var scale=cc.scaleBy(1,2.5);
		var fadeout=cc.fadeOut(0.5)
		var film=this.body.getChildByTag(TAG_FILM);
		var beaker=ll.run.getChildByTag(TAG_BEAKER_ALL);
		film.runAction(cc.sequence(cc.spawn(rotate.reverse(),scale),cc.spawn(move2,cc.callFunc(function() {
			beaker.showLine1();
			this.showFlow();
		}, this)),fadeout));
	},
	callback:function(p){
		var func=cc.callFunc(function() {
			gg.flow.next();
		},this);
		switch (p.getTag()) {
		case TAG_CYLINDER:
			var move=cc.moveTo(1,cc.p(gg.width*0.25, gg.height*0.05));
			var move1=cc.moveTo(1, cc.p(gg.width*0.15, gg.height*0.05));
			var rotate=cc.rotateBy(1,85);
			if(this.getTag()==TAG_CYLINDER_ALL){
				p.runAction(cc.sequence(move,cc.spawn(cc.sequence(rotate,cc.delayTime(2)),cc.callFunc(function() {
					this.filmAction();
				}, this)),rotate.reverse(),cc.callFunc(function() {
					p.setVisible(false);
				},this),func));
			}else if(this.getTag()==TAG_CYLINDER1_ALL){
				p.runAction(cc.sequence(move1,cc.spawn(cc.sequence(rotate,cc.delayTime(2)),cc.callFunc(function() {
					this.filmAction1();
				}, this)),rotate.reverse(),cc.callFunc(function() {
					p.setVisible(false);
				},this),func));
			}
			break;
		default:
			break;
		}
	}
});